package dao.impl;

import hibernate.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import dao.ClienteDAO;
import dominio.Cliente;

public class ClienteDAOImpl implements ClienteDAO {
	
	private static ClienteDAOImpl instancia = null;
	@SuppressWarnings("unused")
	private static SessionFactory sf = null;

	private ClienteDAOImpl(){}
	
	public static ClienteDAOImpl getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ClienteDAOImpl();
		} 
		return instancia;
	}
	public Cliente findByID(Integer id) {
		Cliente cliente = new Cliente();
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction tx= session.beginTransaction();
		session.load(cliente, id);
		tx.commit();
		session.close();
		return cliente;
	}

}
